chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
  chrome.sessions.getRecentlyClosed({ maxResults: 25 }, function(sessions) {
    const tabs = sessions
      .filter(session => session.tab)
      .map(session => session.tab);
    
    chrome.storage.local.set({ closedTabs: tabs });
  });
});